package com.meilingcloud.research.controller;

import com.meilingcloud.common.annotation.Log;
import com.meilingcloud.common.core.controller.BaseController;
import com.meilingcloud.common.core.domain.AjaxResult;
import com.meilingcloud.common.core.page.TableDataInfo;
import com.meilingcloud.common.enums.BusinessType;
import com.meilingcloud.common.utils.SecurityUtils;
import com.meilingcloud.common.utils.poi.ExcelUtil;
import com.meilingcloud.research.domain.RwsQualityEntry;
import com.meilingcloud.research.service.IRwsQualityEntryService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.Arrays;
import java.util.List;

/**
 * 质控条目 Controller
 *
 * @author chenl
 * @date 2021-05-10
 */
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/research/qualityEntry")
public class RwsQualityEntryController extends BaseController {

    private final IRwsQualityEntryService iRwsQualityEntryService;

    /**
     * 查询质控条目 列表
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:list')")
    @GetMapping("/list")
    public TableDataInfo list(RwsQualityEntry rwsQualityEntry) {
        startPage();
        List<RwsQualityEntry> list = iRwsQualityEntryService.queryList(rwsQualityEntry);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('research:qualityEntry:list')")
    @GetMapping("/listAll")
    public AjaxResult listAll() {
        return AjaxResult.success(iRwsQualityEntryService.list());
    }

    /**
     * 导出质控条目 列表
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:export')")
    @Log(title = "质控条目 ", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(RwsQualityEntry rwsQualityEntry) {
        List<RwsQualityEntry> list = iRwsQualityEntryService.queryList(rwsQualityEntry);
        ExcelUtil<RwsQualityEntry> util = new ExcelUtil<RwsQualityEntry>(RwsQualityEntry.class);
        return util.exportExcel(list, "qualityEntry");
    }

    /**
     * 获取质控条目 详细信息
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:query')")
    @GetMapping(value = "/{qcEntryId}")
    public AjaxResult getInfo(@PathVariable("qcEntryId") Long qcEntryId) {
        return AjaxResult.success(iRwsQualityEntryService.getById(qcEntryId));
    }

    /**
     * 新增质控条目
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:add')")
    @Log(title = "质控条目 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody @Valid RwsQualityEntry rwsQualityEntry) {
        rwsQualityEntry.setCreateBy(SecurityUtils.getUsername());
        return toAjax(iRwsQualityEntryService.save(rwsQualityEntry));
    }

    /**
     * 修改质控条目
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:edit')")
    @Log(title = "质控条目 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody @Valid RwsQualityEntry rwsQualityEntry) {
        rwsQualityEntry.setUpdateBy(SecurityUtils.getUsername());
        return toAjax(iRwsQualityEntryService.updateById(rwsQualityEntry));
    }

    /**
     * 删除质控条目
     */
    @PreAuthorize("@ss.hasPermi('research:qualityEntry:remove')")
    @Log(title = "质控条目 ", businessType = BusinessType.DELETE)
    @DeleteMapping("/{qcEntryIds}")
    public AjaxResult remove(@PathVariable Long[] qcEntryIds) {
        return toAjax(iRwsQualityEntryService.removeByIds(Arrays.asList(qcEntryIds)));
    }
}
